package com.sphd.Restaurant.presenter;

import android.util.Log;
import android.widget.Toast;

import com.android.volley.VolleyError;
import com.sphd.Restaurant.infos.RestaurantInfo;
import com.sphd.Restaurant.interfFace.VolleyCallBack;
import com.sphd.Restaurant.utils.VolleyErrorHelper;
import com.sphd.Restaurant.views.AllView;


import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

/**
 * Created by Hu on 2016/10/6.
 */

public class AllRestP extends BasePresenter implements VolleyCallBack<JSONObject> {
    AllView allView;

    public AllRestP(AllView allView) {
        this.allView = allView;
    }

    @Override
    public void addData(String url) {
        allView.showdialog();
        sendJsonObjectUrl(url,this);
    }

    @Override
    public void onResponse(JSONObject jsonObject) {
        Log.e("all===",jsonObject.toString());
        try {
            if (!jsonObject.getString("res") .equals("[]")) {
                List<RestaurantInfo> getmsg = myJson.getAllRestaurantList(jsonObject);
//                List<RestaurantInfo> getmsg = myJson.getPersons(jsonObject.getString("res"),RestaurantInfo.class);
                Log.e("Asize===",getmsg.size()+"");
                allView.refreshList(getmsg);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        allView.dissmissdialog();
    }



    @Override
    public void onErrorResponse(VolleyError error) {
        allView.dissmissdialog();
        allView.Error(error);
        Toast.makeText(context, VolleyErrorHelper.getMessage(error),Toast.LENGTH_SHORT).show();
    }
}
